/*
 * Hyuga: A Density-Grid Stream Clustering Platform. Copyright (C) 2014 PUC-Rio/Laboratory for Advanced Collaboration
 * 
 * Hyuga is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * Hyuga is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with Hyuga. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package br.pucrio.inf.lac.konoha.hyuga.playground;

import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

import br.pucrio.inf.lac.konoha.hyuga.core.Bootstrap;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.ConfigurationEngineDefaults.Threading;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;

/**
 * A CSV playback routine. The csv file must have the following columns: uuid,latitude,longitude,timestamp
 * 
 * Sample File: uuid, latitude, longitude, timestamp 286, -22.9559986550780, -43.1922377359216, 70462 973,
 * -22.9603834270102, -43.2000845051359, 70462 2742, -22.9728237658448, -43.1907249148011, 704637 4075,
 * -22.9788327380116, -43.1908675079309, 70464 878, -22.9811741072085, -43.2333375518404, 70464 3431, -22.9703160507337,
 * -43.1907072643957, 704650 341, -22.9656428061742, -43.2163599814267, 70466 5028, -22.9580526401979,
 * -43.2050608584764, 704664
 *
 * @author Marcos Roriz <mroriz@inf.puc-rio.br>
 */
public class Helper {

    private static final ReentrantLock lock = new ReentrantLock();
    private static int count = 0;
    
    public static int lol(int k) {
        System.out.println(++count + "deu match");
        return k;
    }
    
    public static B[] m(B[] aevents) {
        if (aevents != null) {
            int x = (int) aevents[0].getY();
            B[] events = new B[x];
            for (int i = 0; i < x; i++) {
                events[i] = new B(i);
            }
            return events;
        } else {
            return null;
        }
    }
    
    public static int aff(Collection<?> bsss) {
        return (int) (-100 * Math.random());
    }
    public static boolean zlock() {
        System.out.println("TRY LOCK " + Thread.currentThread().getName());
        lock.lock();
        System.out.println("LOCK " + Thread.currentThread().getName());
        System.out.println(++count + " :: Consegui Pegar o Lock");
        
        return true;
    }
    
    public static boolean zunlock() {
        System.out.println("UNLOCK " + Thread.currentThread().getName());
        System.out.println(count + " :: Fez o Unlock");
        lock.unlock();
        return true;
    }
}
